Gravity Volumes Tutorial

From PreyWiki

Setting up a simple gravity volume.

Drag out a brush that defines the extents of your volume. Right click on the created brush and choose volume_gravity from the popup menu.

Image:Gravity1.jpg
Fig.1: Right click menu

Select the newly created volume_gravity entity and enter a key named 'gravity' to define the direction of the gravity field within the volume. This is a vector key defining gravity strength in X, Y and Z. Standard game gravity is '0 0 -1066'; that is, a force of 1066 in the negative Z direction. The figure below shows a normal gravity volume setup, download and open the grav1.map test map to see an example.

Image:Gravity2.jpg
Fig.2: A standard gravity_volume with inverted gravity.


Changing the state of a gravity volume.

The state of a gravity volume can be altered in two ways. A target_enable and target_disable entity can be used to turn the effect of a volume on and off. Additionally more precise control is available within the level script.

For our example here we will just toggle the state of the volume. In the example map we use a console_projection_eye to allow us to alter the volume, but any standard triggering method will work. Download and examine grav2.map to see how it is set up.

Image:Gravity3.jpg
Fig.3: Using consoles to enable and disable a gravity volume.

Note: There's an undocumented key available on gravity volumes. The key 'enabled' can be set to 0 to prevent a volume being active at map load. More advanced control is available in the form of the script call $entityname.setGravity( vector );


Shoot switches.

Using shoot switches (entity name 'trigger_gravityswitch') to change the state of a gravity volume is very easy. Place a trigger_gravityswitch with an orientation that reflects the direction you wish your new gravity to assume. Have the switch target your gravity_volume and the details are taken care of by the game. In the example map (grav3.map) four switches are placed in four sides of the gravity volume, all the map maker needs do in this case is have each switch target the volume.

Image:Gravity4.jpg
Fig.4: Shoot switches targeting a gravity volume.

It is possible to override this behavior by setting the 'vector' key on the switch. This was not done in Prey as it was felt important to have the switches behave consistently.


Radial gravity.

For planetoids we use a different entity, a 'volume_gravityinward'. The illustration below (taken from grav4.map) shows a simple planetoid using a default volume_gravityinward. No other keys are required in order to set this up, although fine tuning of the behavior is possible using the keys documented in the appendix below.

Image:Gravity5.jpg
Fig.5: Side view of a basic radial gravity volume allowing the player to walk on a planetoid.


Outward gravity.

Although not used in the single player portion of Prey it is possible to use a negative factor with a radial gravity volume. In example map grav5.map the following key was used to allow the player to walk on the inside of a spherical space.

Image:Gravity6.jpg
Fig.6: Using a negative factor to allow the player to walk in the inside of a sphere.

Image:Gravity7.jpg
Fig.7: Top down editor view of an outward gravity volume.


Performance considerations.

Things to bear in mind when designing a gravity rich area.

Use broad strokes to define your gravity volumes. Each additional volume placed in the map adds to the computational overhead. Avoid using many small volumes to fit the layout of your area and blanket large parts with a single volume if at all possible.

“isSimpleBox” is an important key. It defaults true because a non simple volume adds considerable overhead when calculating the behavior required. You will undoubtedly need to set this false on occasion but try to design around it if at all possible.

Don't underestimate the use of smoke and mirrors. Clever use of a portal or a wall walk surface can trick the player into believing they are in an altered gravity area. It's always cheaper to invert the geometry and use standard gravity than to use a gravity_volume.

AI creatures will respond better to a standard gravity orientation so again, think of ways to trick the player if you plan combat in an area of gravity madness.


Appendix.

volume_gravity
A variable sized gravity zone. Changes the gravity of all physics objects that enter.

gravity vector New gravity vector (x y z). Default (0 0 -1066)
interpTime float Time in seconds to interpolate gravity changes. Default (1.0)
reorient boolean Reorient the player to the gravity direction. Default (1)
showVector boolean Draw debug line in game. Default (0)
killmonsters boolean Kill monsters when affected by gravity. Default (1)
zeroGravOnChange boolean
isSimpleBox boolean Simple boxes are cheaper. Default (1)
snd_gravity_loop string Sound played while gravity is non-default.


trigger_gravityswitch
Target at volume_gravity entities. Use angle to specify direction of gravity.

strength float Gravity factor. Default (1.0)
vector vector Forced gravity vector. Overrides strength and angle.
Enabled boolean Initially enabled. Default (1)


volume_gravityinward
A variable sized gravity zone. Gravitates all entering objects towards origin of volume. To make an outward gravity zone use a negative factor.

factor float Percentage of normal gravity magnitude. Default (0.5)
interpTime float Time in seconds to interpolate gravity changes. Default (1.0)
override_origin vector Origin defaults to model origin. Use this to override it.
monster_trace_gravity boolean Monsters trace down to find gravity normal rather than using inward vector. Default (0)
reorient boolean Reorient the player to the gravity direction. Default (1)
showVector boolean Draw debug line in game. Default (0)
killmonsters boolean Kill monsters when affected by gravity. Default (1)
isSimpleBox boolean Simple boxes are cheaper. Default (1)


volume_gravitysink
Variable sized gravity sink zone. Gravitates all entering objects towards origin with force proportional to inverse squared distance.

factor float Gravity factor. Default (60000)
interpTime float Time in seconds to interpolate gravity changes. Default (1.0)
showVector boolean Draw debug line in game. Default (0)
killmonsters boolean Kill monsters when affected by gravity. Default (1)
isSimpleBox boolean Simple boxes are cheaper. Default (1)